package com.wms.db.dao;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.hibernate.criterion.DetachedCriteria;


public interface IBeanDao<T extends Serializable, PK extends Serializable> { 
    // -------------------- find, insert, delete, update action -------------------- 

    // Get object by id. If not find, return null. 
    public T get(PK id); 

    // Get object by id. If not find, throw exception. 
    public T load(PK id); 

    // get all
    public List<T> loadAll(); 

    // update
    public void update(T entity); 

    // add
    public void save(T entity); 

    // add or update
    public void saveOrUpdate(T entity); 
    
    // merge
    public void merge(T entity);
    
    // add or update all
    public void saveOrUpdateAll(Collection<T> entities); 

    // delete
    public void delete(T entity); 

    // delete By key
    public void deleteByKey(PK id); 

    // delete all
    public void deleteAll(Collection<T> entities); 


    // -------------------------------- Criteria ------------------------------ 
    
    /**  
     * @return DetachedCriteria object outside the scope of a session
     */  
    DetachedCriteria createDetachedCriteria();  

    /** 
     * Use database aggregate function
     * @param criteria: a DetacherCriteria object           
     * @return Aggregate value
     */  
    public Object getAggregateValue(DetachedCriteria criteria);
    /** 
     * Find records count by criteria
     * @param criteria: a DetacherCriteria object  
     * @return records count 
     */  
    public Long getRowCountByCriteria(DetachedCriteria criteria);
    /** 
     * Find records by criteria
     * @param criteria: a DetacherCriteria object  
     * @return records found by criteria 
     */
    public List<T> findByCriteria(DetachedCriteria criteria);
    /** 
     * Find records by criteria
     * @param criteria: a DetacherCriteria object   
     * @param firstResult: start row number      
     * @param maxResults: return row count           
     * @return records found by criteria with pagination
     */  
    public List<T> findByCriteria(DetachedCriteria criteria, Integer firstResult, Integer maxResults);

} 